package com.data.enter.module.sys.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.data.enter.base.tips.PageInfoBT;
import com.data.enter.base.tips.SuccessTip;
import com.data.enter.config.PageFactory;
import com.data.enter.module.sys.model.Aaaa;
import com.data.enter.module.sys.service.IAaaaService;
import com.data.enter.utils.ObjectUtils;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ligang
 * @since 2024-03-01
 */
@Controller
@RequestMapping("/aaaa")
@Slf4j
public class AaaaController {

    @Autowired
    private IAaaaService aaaaService;

    @RequestMapping("/findPage")
    @ResponseBody
    public Object findPage() {
        Map<String, Object> paramMap = new HashMap<>();
        Page<Map<String, Object>> page = new PageFactory<Map<String, Object>>().defaultPage(paramMap);
        List<Map<String, Object>> resultList = aaaaService.findPageList(page, paramMap);
        page.setRecords(resultList);
        return new PageInfoBT<>(page);
    }

    @RequestMapping("/save")
    @ResponseBody
    public Object save() {
        Aaaa aaaa = new Aaaa();
        aaaa.setId(ObjectUtils.getShortUuid());
        aaaa.setName("三十多岁");
        aaaaService.save(aaaa);
        return new SuccessTip();
    }

    @RequestMapping("/update")
    @ResponseBody
    public Object update(@RequestBody JSONObject jsonObject) {
        Aaaa aaaa = JSON.toJavaObject(jsonObject,Aaaa.class);
        aaaaService.updateById(aaaa);
        return new SuccessTip();
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id) {
        aaaaService.removeById(id);
        return new SuccessTip();
    }

    /**
     * 导出数据
     * @author ligang
     */
    @RequestMapping("/exportData")
    @ResponseBody
    public Object exportData(HttpServletResponse response, @RequestBody Map<String, Object> paramMap) {
        aaaaService.exportData(response, paramMap);
        return null;
    }

}
